import java.util.ArrayList;
import java.util.Random;
//import java.util.Collections;

//表示一副扑克牌中的一张牌
class Card{
    private String suit;//表示扑克牌的花色
    private String rank;//表示扑克牌的点数

    public Card(String suit, String rank) {
        this.suit = suit;
        this.rank = rank;
    }
    public String getsuit(){
        return suit;
    }

    public String getRank() {
        return rank;
    }

    public void setSuit(String suit){
        this.suit=suit;
    }

    public void setRank(String rank) {
        this.rank = rank;
    }

    @Override
   public String toString(){
        return this.suit+this.rank+"";
    }
}

public class Test {
    public static void main(String[] args) {
        //使用ArrrayList创建一副扑克牌
        ArrayList<Card> Poker=new ArrayList<Card>();
        Poker= creatpoker();
        //打印原始扑克牌
        System.out.println(Poker);
        //打印洗牌后的扑克牌
        //Collections.shuffle(Poker);
         Myshuffle(Poker);
        System.out.println(Poker);
        //将手牌按顺序分给3个人，一个人5张
        //利用ArrayList创建二维数组
        ArrayList<ArrayList<Card>> hands=new ArrayList<ArrayList<Card>>();
        //创建3个人中的手牌
        for (int i = 0; i <3 ; i++) {
            ArrayList<Card> hand=new ArrayList<>();
            hands.add(hand);
        }
        //一次分别发给3个人 循环5次
        for (int i = 0; i <5 ; i++) {
            for (int j = 0; j <3 ; j++) {
                ArrayList<Card> hand=hands.get(j);//hands.get()取的是Card数组 用hand.get()取的是每个Card
                Card card=Poker.remove(0);
                 hand.add(card);
            }
        }
        //打印每个人的手牌
        for (int i = 0; i <3 ; i++) {
            System.out.println("第"+(i+1)+"个人的手牌："+hands.get(i));
        }

    }
    public static void Myshuffle(ArrayList<Card> poker1){
         Random random=new Random();
         for (int i=0;i< poker1.size();i++){
             int s=random.nextInt(poker1.size());
             Card temp=new Card(poker1.get(i).getsuit(),poker1.get(i).getRank());
             poker1.set(i,poker1.get(s));
             poker1.set(s,poker1.get(i));


         }
    }
        //创建一副扑克牌
    public static ArrayList<Card> creatpoker(){
        ArrayList<Card> poker=new ArrayList<Card>();
        String []suits= {"方块","♥","♠","♣"};
        for (String s:suits){
            for (int i = 1; i <= 10; i++) {
                Card card=new Card(s,""+i);
                poker.add(card);
            }
             Card rank1=new Card(s,"J");
             Card rank2=new Card(s,"Q");
             Card rank3=new Card(s,"K");
             poker.add(rank1);
             poker.add(rank2);
             poker.add(rank3);
        }
        return poker;
    }



}
